package org.itstack.state.order;

/**
 * 已送达状态
 * 订单已送达，等待用户确认收货
 * 
 * 设计原则：
 * - 单一职责：只负责已送达状态的行为
 * - 里氏替换：可以替换抽象订单状态
 */
public class DeliveredState implements OrderState {
    
    @Override
    public String getStateName() {
        return "已送达";
    }
    
    @Override
    public String getStateDescription() {
        return "订单已送达，等待用户确认收货";
    }
    
    @Override
    public void handleAction(OrderContext context, OrderAction action) {
        switch (action) {
            case COMPLETE:
                System.out.println(String.format("订单 %s 已完成，用户确认收货", context.getOrderId()));
                context.setState(new CompletedState());
                break;
            case REFUND:
                System.out.println(String.format("订单 %s 申请退款，金额: %.2f", 
                    context.getOrderId(), context.getAmount()));
                context.setState(new CancelledState());
                break;
            default:
                System.out.println(String.format("订单 %s 在已送达状态下无法执行 %s 操作", 
                    context.getOrderId(), action.getName()));
        }
    }
    
    @Override
    public boolean canExecuteAction(OrderAction action) {
        return action == OrderAction.COMPLETE || action == OrderAction.REFUND;
    }
}
